package com.uniview.utils;


import com.uniview.eumn.CommonEnum;
import com.uniview.exception.CommonException;

import java.util.Map;

/**
 * created by lux
 */
public class AssertUtils {
    /**
     * 校验所传入的字符串是否为空,如果为空就报错
     */
    public static void strIsEmpty(String str, String msg) throws Exception {
        if (null == str || str.length() <= 0) {
            throw new CommonException(CommonEnum.FAIL_CODE, CommonEnum.FAIL_MSG);
        }
    }

    /**
     * 校验所传入的对象是否为空,如果为空就报错
     */
    public static void isNull(Object obj, String msg) throws Exception {
        if (null == obj) {
            throw new CommonException(CommonEnum.FAIL_CODE, CommonEnum.FAIL_MSG);
        }
    }

    /**
     * 检验多参数不为空
     *
     * @param checkStr
     * @param checkMap
     * @throws Exception
     */
    public static void strsIsEmpty(String checkStr, Map<String, Object> checkMap) throws Exception {
        String[] params = checkStr.split("\\|");
        for (String param : params) {
            if (!StringUtils.checkIsStrNull(param)) {
                strIsEmpty(checkMap.get(param) == null ? "" : checkMap.get(param).toString(), "请求参数" + param + "为空");
            }
        }
    }
}
